
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
*
* Bachelor thesis at the Institute of Biomedical Engineering, 
* located at the UMIT/EWZ campus in Hall in Tyrol. <br><br>
* 
* The class generates a JFrame for showing the segmentation progress and the 
* segmentation time left.
* 
* @author Stefan fuchs
*
*/
public class StatusDialog{
	
///////////////////////
///////Variables///////
///////////////////////
	
//Swing objects
	/**JLabel for showing the current status */
	private JLabel lblStatus;
	
	/**JLabel for showing the time left */
	private JLabel lblTime;
	
	/** JDialog for viewing the status */
	private JFrame jfDialog;
	
	/** JButton to abort calculating */
	private JButton btnAbort;	


	
///////////////////////
////////Methods////////
///////////////////////
	
	/**
	 * StatusDialog constructor
	 */
	public StatusDialog(){
		try {
			UIManager.setLookAndFeel(
		            UIManager.getSystemLookAndFeelClassName());
			this.jfDialog = new JFrame();
			this.lblStatus = new JLabel();
			this.lblTime = new JLabel();
			this.btnAbort = new JButton("Abort");
		}catch (UnsupportedLookAndFeelException e){}
	     catch (ClassNotFoundException e){}
	     catch (InstantiationException e){}
	     catch (IllegalAccessException e){}
		
	    Toolkit toolkit = Toolkit.getDefaultToolkit();
		Dimension screenSize = toolkit.getScreenSize();
        GridBagConstraints gbc = new GridBagConstraints();
        
        this.jfDialog.getContentPane().setLayout(new GridBagLayout());
        this.jfDialog.setResizable(false);
        this.jfDialog.setSize(300, 120);
        this.jfDialog.setIconImage(null);
        this.jfDialog.setLocation((screenSize.width - 200) / 2, (screenSize.height - 120) / 2);

        gbc.insets = new Insets(5,5,5,5);
        gbc.gridx = 0;
        gbc.gridy = 0;
        this.jfDialog.add(lblStatus, gbc);
        
        gbc.gridy++;
        this.jfDialog.add(lblTime, gbc); 
        
        gbc.gridy++;
        this.jfDialog.add(btnAbort, gbc); 
	}
	
	
	/**
	 * Shows the StatusDialog
	 */
	public void show(boolean abort){
		this.btnAbort.setVisible(abort);
		this.btnAbort.setEnabled(abort);
		this.jfDialog.setVisible(true);
		this.jfDialog.setFocusable(true);
		this.jfDialog.toFront();
	}
	
	
	/**
	 * Close the opened StatusDialog.
	 */
	public void close(){
		this.jfDialog.setVisible(false);
		this.jfDialog.setEnabled(false);
		this.jfDialog.dispose();
		System.gc();
	}
	
	
	
///////////////////////
////Getter & Setter////
///////////////////////	
	
	/**
	 * Sets the status message.
	 * 
	 * @param 	status
	 * 				Status message of the StatusDialog
	 */
	public void setStatus(String status) {
		this.lblStatus.setText(status);
	}


	/**
	 * Sets the left time.
	 * 
	 * @param 	time
	 * 				Segmentation time left
	 */
	public void setTime(String time) {
		this.lblTime.setText(time);
	}


	/**
	 * Gets the JFrame jfDialog
	 * 
	 * @return	jfDialog
	 */
	public JFrame getJfDialog() {
		return this.jfDialog;
	}


	/**
	 * Sets the StatusDialog title.
	 * 
	 * @param 	title
	 * 				Title of the StatusDialog
	 */
	public void setTitle(String title) {
		this.jfDialog.setTitle(title);
	}

	
	/**
	 * Gets the JButton btnAbort
	 * 
	 * @return	btnAbort
	 */
	public JButton getBtnAbort() {
		return this.btnAbort;
	}
}
